import Vue from 'vue'
import VueRouter from 'vue-router'
import HomeView from '../views/HomeView.vue'
import commodity from '@/views/commodity/classify.js'
import data from '@/views/data/data.js'
import jurisdiction from '@/views/jurisdiction/jurisdiction.js'
import user from '@/views/user/user.js'
import order from '@/views/order/order.js'
Vue.use(VueRouter)
const routes = [
  {
    path: '/',
    name: 'home',
    component: HomeView,
    redirect: '/about',  // 重定向:重新指向其它path,会改变网址
    children: [
      {
        path: '/about',
        name: 'about',
        // route level code-splitting
        // this generates a separate chunk (about.[hash].js) for this route
        // which is lazy-loaded when the route is visited.
        component: () => import(/* webpackChunkName: "about" */ '../views/about.vue')
      },
      ...commodity,
      ...data,
      ...jurisdiction,
      ...user,
      ...order
    ],
  },
  {
    path: '/login',
    name: 'login',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ '../views/login.vue')
  },
]

const router = new VueRouter({
  routes
})
router.beforeEach((to, from, next) => {
  if (to.path == '/login') {
    next()
  } else {
    if (localStorage.getItem('houtaitoken')) {
      next()
    } else {
      next('/login')
    }
  }
})
export default router
